define(function (require, exports, module) {
    var Validator = require("./common/validator.js");
    require("./common/dialog");

    var FormValidator = {
        editValidator: function (element) {
            var v = new Validator({
                attrs: {itemClass: "test"},
                element: element,
                autoSubmit: false,
                onFormValidated: function (err, results, form) {
                    if (!err) {
                        $.ajax({
                            url: window.jkconfig.webapiurlv + "login",
                            type: 'POST',
                            data: $("#editForm").serialize(),
                            success: function (data) {
                                console && console.log(data);
                                if (data.code == 0) {
                                    var token = data.token;
                                    localStorage.setItem("api_key", token);
                                    localStorage.setItem("userName", $("#userName").val());
                                    localStorage.setItem("platformId",data.platformId);
                                    localStorage.setItem("platformName",data.platformName);
                                    parent.location.href = 'index.html';
                                    // }else{
                                    //     localStorage.clear();
                                    // }
                                } else {
                                    $.showErr(data.msg);
                                }
                            }
                        });

                    }
                    return false;
                },
                failSilently: true
            });
            v.addItem({
                element: '[name=userName]',
                required: true,
                display: '用户名',
                rule: 'userName'
            }).addItem({
                element: '[name=passWord]',
                required: true,
                display: '密码',
                rule: 'numberOrLetter'
            });
        }
    };
    module.exports = FormValidator;
});